<?xml version="1.0" encoding="UTF-8"?>

<!-- Copyright 2007 XBRL International. All Rights Reserved. -->

<link:linkbase
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:link="http://www.xbrl.org/2003/linkbase"
  xmlns:generic="http://xbrl.org/2008/generic"
  xmlns:va="http://xbrl.org/2008/assertion/value"
  xmlns:variable="http://xbrl.org/2008/variable"
  xmlns:cf="http://xbrl.org/2008/filter/concept"
  xmlns:gf="http://xbrl.org/2008/filter/general"
  xmlns:pf="http://xbrl.org/2008/filter/period"
  xmlns:xfi="http://www.xbrl.org/2008/function/instance" 
  xmlns:label="http://xbrl.org/2008/label"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:test="http://abc.com/test"
  xmlns:xbrli="http://www.xbrl.org/2003/instance"

  xsi:schemaLocation="
  http://www.xbrl.org/2003/linkbase http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd
  http://xbrl.org/2008/generic ../../core_schemas/generic-link.xsd
  http://xbrl.org/2008/formula ../../core_schemas/formula.xsd
  http://xbrl.org/2008/variable ../../core_schemas/variable.xsd
  http://xbrl.org/2008/filter/concept ../../core_schemas/concept-filter.xsd
  http://xbrl.org/2008/filter/period ../../core_schemas/period-filter.xsd
  http://xbrl.org/2008/filter/general ../../core_schemas/general-filter.xsd
  http://xbrl.org/2008/label http://www.xbrl.org/2008/generic-label.xsd
  ">
  
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/element-label" xlink:href="http://www.xbrl.org/2008/generic-label.xsd#element-label" xlink:type="simple"/>
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/variable-set" xlink:href="../../core_schemas/variable.xsd#variable-set" xlink:type="simple"/>
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/variable-filter" xlink:href="../../core_schemas/variable.xsd#variable-filter" xlink:type="simple"/>
  <link:roleRef roleURI="http://www.xbrl.org/2008/role/link" xlink:href="../../core_schemas/generic-link.xsd#standard-link-role" xlink:type="simple"/>
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/variable-set-precondition" xlink:href="../../core_schemas/variable.xsd#variable-set-precondition" xlink:type="simple"/>  <link:roleRef roleURI="http://www.xbrl.org/2008/role/link" xlink:href="../../core_schemas/generic-link.xsd#standard-link-role" xlink:type="simple"/>
  <link:roleRef roleURI="http://www.xbrl.org/2008/role/label/satisfied" xlink:href="../formula-roles.xsd#label-satisfied" xlink:type="simple"/>
  <link:roleRef roleURI="http://www.xbrl.org/2008/role/label/notSatisfied" xlink:href="../formula-roles.xsd#label-not-satisfied" xlink:type="simple"/>

  <generic:link xlink:type="extended"
    xlink:role="http://www.xbrl.org/2008/role/link">

    <!-- $threshold is tolerance for mismatch in the test case -->
    <variable:parameter xlink:type="resource" xlink:label="p_threshold"
     name="threshold" as="xs:decimal" 
     select="0.01"
     xmlns="http://xbrl.org/2008/formula/conformance/parameter"
     />

    <va:valueAssertion xlink:type="resource" 
      xlink:label="calc-linkbase-assertion"
      id="calc-linkbase-assertion"
      aspectModel="non-dimensional" implicitFiltering="false" 
      test="abs( $parent - sum($weightedChildValues) ) le $threshold" />

    <!-- Label for the assertion results -->
    <label:label xlink:type="resource" xlink:label="calc-linkbase-assertion-message" 
      xlink:role="http://www.xbrl.org/2008/role/label/notSatisfied" 
      xml:lang="en">Inconsistent: {node-name($parent)} in context {$parent/@contextRef}, reported value {$parent}, computed value {sum($weightedChildValues)}, test threshold {$threshold}</label:label>   

    <label:label xlink:type="resource" xlink:label="calc-linkbase-assertion-message" 
      xlink:role="http://www.xbrl.org/2008/role/label/satisfied" 
      xml:lang="en">Consistent: {node-name($parent)} in context {$parent/@contextRef}</label:label>   
                                                                        
    <generic:arc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/element-label"
      xlink:from="calc-linkbase-assertion" xlink:to="calc-linkbase-assertion-message" order="1.0"/>

    <!-- function xfi:navigate-relationships -->
    <variable:function xlink:type="resource" xlink:label="navigate-relationships"
       name="xfi:navigate-relationships"
       output="xs:anyAtomicType*">
         <!-- source concept to begin navigation -->
         <variable:input type="xs:QName" />
         <!-- link role -->
         <variable:input type="xs:anyURI" />
         <!-- arc role -->
         <variable:input type="xs:anyURI" />
         <!-- axis (child, parent, etc) -->
         <variable:input type="xs:string" />
         <!-- generations limit or zero for unlimited -->
         <variable:input type="xs:integer" />
         <!-- QNames of arc attributes to return -->
         <variable:input type="xs:QName*" />
    </variable:function>

    <!--  Fact variables.  Note that no general variables are used in this calc-linkbase-assertion. -->
    <variable:factVariable xlink:type="resource" xlink:label="v_parent"   bindAsSequence="false" />
    <!--  Family have same aspects as parent -->
    <variable:factVariable xlink:type="resource" xlink:label="v_family" bindAsSequence="true" />

    <!--  Arc from the calc-linkbase-assertion to the variables it depends on -->
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="calc-linkbase-assertion" xlink:to="p_threshold" order="1.0"
      name="threshold" />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="calc-linkbase-assertion" xlink:to="v_parent" order="1.0"
      name="parent" />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="calc-linkbase-assertion" xlink:to="v_family" order="1.0"
      name="family" />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="calc-linkbase-assertion" xlink:to="v_weightedChildValues" order="1.0"
      name="weightedChildValues" />
    <!--  Arcs from variables to their concept filters -->
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="v_family" xlink:to="f_family" order="1.0"/>

    <!-- cover concept aspect to allow family facts to bind -->
    <cf:conceptSubstitutionGroup strict="false" xlink:type="resource" xlink:label="f_family">
      <cf:substitutionGroup><cf:qname>xbrli:item</cf:qname></cf:substitutionGroup>
    </cf:conceptSubstitutionGroup>

    <!-- general variable is sequence of children (QName, weight)* -->
    <variable:generalVariable xlink:type="resource" xlink:label="rels" bindAsSequence="true"
      select="xfi:navigate-relationships(
                node-name($parent), 
                '',
                'http://www.xbrl.org/2003/arcrole/summation-item',
                'descendant',
                1,
                (QName('','weight'))
                )"  />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="calc-linkbase-assertion" xlink:to="rels" order="1.0"
      name="rels" />

    <!-- general variable is sequence of weighted children values -->
    <variable:generalVariable xlink:type="resource" xlink:label="v_weightedChildValues" bindAsSequence="true"
      select="for $child in $family,
                  $r in 1 to (count($rels) idiv 2) return
              (if ($rels[$r*2-1] eq node-name($child))
               then ($child * $rels[$r*2])
               else () )" /> 

    <!-- precondition, don't fire test if no children -->
    <variable:precondition xlink:type="resource" xlink:label="precondition" 
     test="exists($weightedChildValues)" />
    <generic:arc xlink:type="arc" xlink:to="precondition" xlink:from="calc-linkbase-assertion" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set-precondition" />

  </generic:link>

</link:linkbase>
